<template>
  <transition name="slide">
    <music-list :title="title" :bg-image="bgImage" :songs="songs"></music-list>
  </transition>
</template>

<script type="text/ecmascript-6">
import MusicList from '@/components/music-list/music-list'
import { getSongList } from '@/api/recommend'
import { ERR_OK } from '@/api/config'
import { mapGetters } from 'vuex'
import { createSong } from '@/assets/js/song'

export default {
  computed: {
    ...mapGetters(['disc']),
    title() {
      return this.disc.username
    },
    bgImage() {
      return this.disc.cover
    }
  },
  data() {
    return {
      songs: []
    }
  },
  created() {
    this._getSongList()
  },
  methods: {
    async _getSongList() {
      if (!this.disc.content_id) {
        this.$router.push('/recommend')
        return
      }
      let res = await getSongList(this.disc.content_id)
      if (res.data.result >= 0) {
        res = res.data.data
        console.log(res)
        this.songs = this._normalizeSongs(res.songlist)
      }
    },
    _normalizeSongs(list) {
      let ret = []
      list.forEach((musicData) => {
        if (musicData.songid && musicData.albumid) {
          ret.push(createSong(musicData))
        }
      })
      return ret
    }
  },
  components: {
    MusicList
  }
}
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
.slide-enter-active, .slide-leave-active {
  transition: all 0.3s;
}

.slide-enter, .slide-leave-to {
  transform: translate3d(100%, 0, 0);
}
</style>